<template>
	<!-- 顶部导航栏 -->
	<view class="boxc">
		<image class="boxc_bg" src="https://img.jingkakeji.com/img/static/leave_blank.png" mode="aspectFill"></image>
		<view class="leave_black">

		</view>
		<view class="tops">
			<view class="tops_left" v-if="showTitle">
				<div class="card">
					<!-- 左侧图片 -->
					<img class="card-img" :src=" title.avatar" />

					<!-- 右侧内容（Flex 垂直排列） -->
					<div class="card-content">
						<!-- 右上大文字 -->
						<div class="title-container">
							<div class="title">{{this.title.name}}</div>
							<div class="vip-badge">
								<!-- <img class="small-img" src="/static/mengban.png" alt="vip" /> -->
								<view class="small-img">
									<image src="https://img.jingkakeji.com/img/static/mengban.png" mode="aspectFit">
									</image>
								</view>
								<text style="color: #d6d3ec; font-style: oblique;">VIP{{title.vip_level}}</text>
							</div>
						</div>

						<!-- 右下小图片+文字（Flex 水平排列） -->
						<div class="footer">
							<!-- 			      <img class="small-img" src="/static/offers.png" alt="小图标" />
			      <span style="color: #d6d3ec;">{{title.bean}}</span> -->
							<!-- <img class="small-img" src="/static/lucky/mony.png" alt="小图标" /> -->
							<view class="small-img">
								<image src="https://img.jingkakeji.com/img/static/lucky/mony.png" mode="aspectFit">
								</image>
							</view>
							<text style="color: #FEC530;">{{title.bean}}</text>
						</div>

					</div>
				</div>
			</view>
			<view class="no_login" v-else @click="to_login">
				点我登录
			</view>
			<view class="tops_right">
				<!-- <image style="width: 50rpx;height: 10rpx;margin-top: 40rpx;margin-right: 30rpx;" src="/static/联合 2.png"
					mode=""></image> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUsetInof
	} from "../../api/outOfTheFree/index.js"
	export default {
		props: {
			title: {
				type: Object,
				default: "默认标题"
			},

		},
		data() {
			return {
				data: [],
				showTitle: false,
				boxcHeight: "170rpx",
				leave_blackHeight: "70rpx"

			}
		},
		watch: {
			// 监听props变化
			title: {
				handler(newVal) {
					let token = uni.getStorageSync('token')
					if (token && newVal && Object.keys(newVal).length > 0) {
						this.showTitle = true
					} else {
						this.showTitle = false
					}
				},
				immediate: true,
				deep: true
			}
		},
		mounted() {
			console.log(this.title, "首页用户信息"); // 接收父组件值
			let token = uni.getStorageSync('token')
			if (token) {
				this.showTitle = true
			}
		},
		onShow() {
			// 每次显示时重新检查token状态
			let token = uni.getStorageSync('token')
			if (token && this.title && Object.keys(this.title).length > 0) {
				this.showTitle = true
			} else {
				this.showTitle = false
			}
		},
		methods: {
			to_login() {
				uni.navigateTo({
					url: "/pages/Login/Login"
				})
			}
		}
	}
</script>

<style lang="scss">
	.boxc {
		width: 100vw;
		/* #ifdef APP-PLUS */
		height: 170rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 90rpx;
		/* #endif */
		position: relative;

		.boxc_bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: 0;
		}
	}

	.leave_black {
		width: 100%;
		/* #ifdef APP-PLUS */
		height: 70rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 0rpx;
		/* #endif */
		position: relative;
		z-index: 1;
	}

	.tops {
		width: 100%;
		height: 90rpx;
		position: relative;
		z-index: 1;
		margin: 0;
		padding: 0;

		/* 确保图片不平铺 */
		background-repeat: no-repeat;

		/* 让图片居中显示 */
		background-position: center;

		/* 关键属性：让图片覆盖整个容器，保持比例，可能裁剪部分图片 */
		background-size: contain;

		top: 0;
		display: flex;
		z-index: 9999;
	}

	.tops_left {
		width: 60%;
		height: 100%;
	}

	.no_login {
		text-indent: 50rpx;
		color: #464646;
	}

	.tops_right {
		width: 40%;
		height: 100%;
		display: flex;
		justify-content: flex-end;
		/* 所有子元素靠右 */
	}

	.card {
		display: flex;
		/* 整体横向排列 */
		gap: 14px;
		/* 左侧图片和右侧内容的间距 */
		align-items: flex-start;
		/* 顶部对齐 */
		margin-top: 5rpx;
		// padding: 12px;
		// border: 1px solid #eee;
	}

	.card-img {
		width: 64rpx;
		/* 左侧图片宽度 */
		height: 64rpx;
		/* 高度自适应 */
		object-fit: cover;
		/* 防止图片变形 */
		padding: 10rpx;
		border-radius: 20%;
	}

	.card-content {
		display: flex;
		flex-direction: row;
		/* 右侧内容垂直排列 */
		align-items: center;
		gap: 10px;
		/* 主标题和副标题的间距 */
	}


	.title {
		font-size: 16px;
		font-weight: bold;
		color: white;
		white-space: nowrap;
	}

	.footer {
		margin-top: 20rpx;
		margin-left: 60rpx;
		display: flex;
		/* 右下小图片+文字横向排列 */
		align-items: center;
		/* 垂直居中 */
		gap: 4px;
		/* 小图标和文字的间距 */
		font-size: 12px;
		color: #666;
	}

	.small-img {
		width: 12px;
		height: 12px;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.vip-badge {
		display: flex;
		/* 右下小图片+文字横向排列 */
		align-items: center;
		/* 垂直居中 */
		gap: 4px;
		/* 小图标和文字的间距 */
		font-size: 12px;
		font-weight: bold;
	}
</style>